package CutLoad.components
{
	import CutLoad.Base;
	import CutLoad.cookies.CArray;
	
	import flash.events.MouseEvent;
	/**
	 * 复选框 或单选框的一个单元 
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 
	 */	
	public class CCheckBoxItem extends Base
	{
		private var btnNoSelect:CButton,btnSelect:CButton;
		private var Label:CTextField;
		//用到的两组皮肤
		private var arrSkinNoSelect:Array=null,arrSkinSelect:Array=null;
		private var funClick:Function=null;
		/**
		 * 
		 * @param strLabel 标签
		 * @param spaceX 选框和标签之前的间距
		 * @param funClick 点击调用的方法.格式:function(me:CCheckBoxItem)
		 * 
		 */		
		public function init(strLabel:String,spaceX:Number=5,funClick:Function=null):void{
			if(arrSkinNoSelect==null||arrSkinSelect==null) setSkin(Skin.getInstance().getSkin(6)[0],Skin.getInstance().getSkin(6)[1]);
			//
			btnNoSelect=getOneItem(false);
			btnNoSelect.show(this);
			btnSelect=getOneItem();
			btnSelect.show(this);
			setSelect(false)
			//
			this.funClick=funClick;
			//
			//
			btnSelect.addEventListener(MouseEvent.CLICK,selectClick);
			btnNoSelect.addEventListener(MouseEvent.CLICK,selectClick);
			//
			Label=new CTextField();
			Label.init(strLabel);
			Label.mouseChildren=false;
			Label.mouseEnabled=false;
			Label.setXY(btnSelect.width+spaceX,btnSelect.y);
			Label.show(this);
		}
		public function setSkin(arrNoSelect:Array,arrSelect:Array):void{
			arrSkinNoSelect=arrNoSelect;
			arrSkinSelect=arrSelect
		}
		/**
		 * 获得文本标签 
		 * @return 
		 * 
		 */		
		public function get lable():String{
			return Label.text;
		}
		/**
		 * 设置选重或不选重 
		 * @param isSelect
		 * 
		 */		
		private function setSelect(isSelect:Boolean=true):void{
			if(!isSelect){
				btnNoSelect.visible=true;
				btnSelect.visible=false
			}else{
				btnNoSelect.visible=false;
				btnSelect.visible=true;
			}
		}
		/**
		 * 获得不是选重了 
		 * @return 
		 * 
		 */	
		public function get value():Boolean{
			return btnSelect.visible;
		}
		/**
		 * 设置选重或不选重 
		 * @param isSelect true 选重, false 不选重
		 * @return 
		 * 
		 */		
		public function set value(isSelect:Boolean):void{
			setSelect(isSelect);
		}
		private function selectClick(e:MouseEvent):void{
			var btn:CButton=e.target as CButton;
			if(btn==btnSelect){
				setSelect(false);
			}else{
				setSelect(true);
			}
			if(funClick!=null) funClick(this)
		}
		private function getOneItem(isSelect:Boolean=true):CButton{
			var btn:CButton=new CButton();
			if(isSelect){
				btn.setSkin(arrSkinSelect,"");
			}else{
				btn.setSkin(arrSkinNoSelect,"");
			}
			btn.init();
			return btn;
		}
	}
}